const Koa = require('koa');
const Router = require('koa-router');
const app = new Koa();
const router = new Router();
const serve = require('koa-static');
const send = require('koa-send');
const bodyParser = require('koa-bodyparser')
const session = require('koa-session')

// app.use(async (ctx, next) => {
// 	const start = Date.now();
// 	console.log('1', start);
// 	await next();
// 	console.log('3', Date.now());
// 	ctx.body = 'Hello Koa';
// })
// const config = {
// 	keys: 'hhhh'
// }
app.keys = 'tryyit'
app.use(session(app))
app.listen(3003)
app.use(bodyParser());


// 有问题喔！
// router.get('/cat', (ctx, next) => {
// 	send(ctx, 'cat.jpg').catch(err => console.log(err))
// })


// koa-session也有问题！
router.post('/user', async (ctx, next) => {
	// let n = ctx.session.views || 0;
	// ctx.session.views = ++n;
	ctx.body = 'hh';
})

app
  .use(router.routes())
  .use(router.allowedMethods());